package com.report.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.report.entity.DownloadReport;
import com.report.service.DownloadReportService;
import com.report.service.IReportService;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author summer
 * @date 2024-07-03 19:34
 */
@RestController
@RequestMapping(value = "/webUpload")
@AllArgsConstructor
@CrossOrigin
public class WebUploadController {

          private final IReportService reportService;

          @GetMapping(value = "/downloadReportFile/{id}")
          public void downloadReportFile(@PathVariable Integer id, HttpServletResponse response) {

              reportService.downloadReportFile(id,response);
          }

         private final DownloadReportService downloadReportService;


          @GetMapping(value = "/memberDownloadReportNum/{reportId}")
          public Result<String> memberDownloadReportNum(@PathVariable Integer reportId) {
              LambdaQueryWrapper<DownloadReport> eq = Wrappers.lambdaQuery(DownloadReport.class).eq(DownloadReport::getReportId, reportId).eq(DownloadReport::getMemberId, StpUtil.getLoginId());
              DownloadReport one = downloadReportService.getOne(eq);
              if(ObjectUtil.isEmpty(one)){
                  downloadReportService.findMemberDownloadReportFile();;
              }
              return Result.successResult();
          }


}
